﻿using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ArmyCreator.ViewModels
{
    public class ArmyViewModel : ALoadable<DataModel.Army>, INotifyPropertyChanged
    {

        #region FIELDS
        public int Id
        {
            get { return LoadedModel.Id; }
            set { LoadedModel.Id = value; NotifyPropertyChanged("Id"); }
        }

        public String Name
        {
            get { return LoadedModel.Name; }
            set { LoadedModel.Name = value; NotifyPropertyChanged("Name"); }
        }

        public int Points
        {
            get { return LoadedModel.Points; }
            set { LoadedModel.Points = value; NotifyPropertyChanged("Points"); }
        }

        public int Max
        {
            get { return LoadedModel.WantedPoints; }
            set { LoadedModel.WantedPoints = value; NotifyPropertyChanged("Max"); }
        }
        #endregion

        public ArmyViewModel()
        {
            LoadData(new DataModel.Army(), 1); IsDataLoaded = false;
        }

        protected override void Load(DataModel.Army model, int depth)
        {
            NotifyPropertyChanged("Id");
            NotifyPropertyChanged("Name");
            NotifyPropertyChanged("Points");
            NotifyPropertyChanged("Max");
        }

        #region NOTIFICATIONS
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
